# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=gn
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=0.2200.95b0f8fe
pkgrel=1
pkgdesc='Meta-build system that generates build files for Ninja (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://gn.googlesource.com/gn/"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python"
             "git")
_commit=95b0f8fe31a992a33c040bbe3867901335c12762
source=(git+https://gn.googlesource.com/gn#commit=$_commit
        001-build-fixes.patch
        003-remove-msvc-flags.patch
        004-add-arm64-arch.patch)
sha256sums=('SKIP'
            '01045719f76a1127dc54586b8f1dc6111cc6210440d1d72a0afbc876d29d3c36'
            '67f58d677f63bf5e9919f63d68afa007b1a2d14c5fae13cd5487bd1c41cf69de'
            '1cd84e9f2c8e4daf4bdb12ae7accc15b57d3f2abf87ff40ebf2c5e180ddeca3f')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

pkgver() {
  cd ${_realname}
  echo 0.$(git rev-list --count initial-commit..).$(git rev-parse --short=8 HEAD)
}

prepare() {
  cd ${_realname}

  apply_patch_with_msg \
    001-build-fixes.patch \
    003-remove-msvc-flags.patch \
    004-add-arm64-arch.patch
}

build() {
  cd ${_realname}
  ./build/gen.py --allow-warnings --no-static-libstdc++

  ninja -C ./out
}

package() {
  cd ${_realname}

  install -Dm755 out/gn.exe "${pkgdir}${MINGW_PREFIX}/bin/gn.exe"
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}" docs/*
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/vim/vimfiles"
  cp -r misc/vim/{autoload,ftdetect,ftplugin,syntax} \
    "${pkgdir}${MINGW_PREFIX}/share/vim/vimfiles/"
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/emacs/site-lisp" misc/emacs/gn-mode.el
}

# vim:set ts=2 sw=2 et:
